* MDS of party positions (derived from thermometers)

version 13.1

* Get data
use querschnitt-2013.dta , replace 

* rename variables

foreach partei in union spd fdp linke gruene afd {
	ren skalo`partei' `partei'
	}



* Restrict analysis to pre-election data to avoid contamination by coalition negotiations
set scheme tufte

forvalues region = 0/1 {
	qui corr union spd fdp linke gruene afd if distostwest == `region' & nachwahl == 0
	matrix R = r(C)
* Preserve labels
	local rnames : rownames R
	local cnames : colnames R
* MDS needs measure of similarity
* Halve correlations and add  0.5
	matrix R=R*.5
	matrix pluseinhalb=J(6,6,.5)

* Use matrix labels
	matrix rownames pluseinhalb = `rnames'
	matrix colnames pluseinhalb = `cnames'
	matrix R=R+pluseinhalb
* MDS
	mdsmat R,shape(full) s2d(oneminus) noplot 
* Stress?
	estat stress
* Generate plots
* and export them 
	if `region' == 0 {
		local rnote = "Region: West"
		}
	else {
		local rnote = "Region: Ost"
		}
	mdsconfig, title("") note("`rnote'") xscale(range(-0.4 0.4)) yscale(range(-0.4 0.4)) xlabel(-0.4(.2).4) ylabel(-0.4(.2).4,  nogrid )
	graph export "mds-`region'.eps", replace 
	estat config
	}

